<script>
export default {
onLaunch: function() {
    console.log('App Launch')
    
    // 检查登录状态
    const token = uni.getStorageSync('token')
    if (token) {
      console.log('Found token, fetching user info...')
      // 使用 Vuex store 获取用户信息
      this.$store.dispatch('user/fetchUserInfo').then(() => {
        console.log('User info fetched successfully')
      }).catch(error => {
        console.error('Failed to fetch user info:', error)
        // 如果获取用户信息失败，清除无效的 token
        this.$store.dispatch('user/clearUser')
      })
	} else {
      console.log('No token found')
	}
},
onShow: function() {
    console.log('App Show')
    
    // 检查登录状态
    const isLoggedIn = this.$store.getters['user/isLoggedIn']
    console.log('User logged in:', isLoggedIn)
	
	if (isLoggedIn) {
      const userInfo = this.$store.getters['user/userInfo']
      console.log('User info:', userInfo)
	}
},
onHide: function() {
    console.log('App Hide')
  }
}
</script>

<style>
/*每个页面公共css */ 
</style>
